/*
 * Created on Oct 13, 2005 6:44:02 AM
 * 
 * $Id: MemoryWritableByteStream.java,v 1.1 2005/10/16 14:15:04 olu Exp $
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package tripleo.framework.io;

import java.nio.ByteBuffer;

class MemoryWritableByteStream implements WritableByteStream {
	private ByteBuffer backing;
	private int mSize;
	private int mRead;
	
	public MemoryWritableByteStream(int aSize) {
		mSize   = aSize;
		mRead   = 0;
		backing = ByteBuffer.allocate/*Direct*/(aSize);
	}

	public long available() {
		return mSize - mRead;
	}

	public void write(ReadableByteStream aStream) {
		backing.put(aStream.array());
	}

	public ReadableByteStream reader() {
		return new MemoryReadableByteStream(backing);
	}
}
